package com.yuba.front.controller.fishSite;

import cn.dev33.satoken.annotation.SaIgnore;
import com.yuba.common.core.domain.R;
import com.yuba.common.mybatis.core.page.PageQuery;
import com.yuba.common.mybatis.core.page.TableDataInfo;
import com.yuba.common.satoken.utils.LoginHelper;
import com.yuba.common.web.core.BaseController;
import com.yuba.front.domain.bo.FishSiteBo;
import com.yuba.front.domain.param.DelParam;
import com.yuba.front.domain.param.FishSiteParam;
import com.yuba.front.domain.vo.FishSiteDetailVo;
import com.yuba.front.domain.vo.FishSiteVo;
import com.yuba.front.service.IFishSiteService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 鱼塘API接口
 *
 * @author modakai
 */
@RestController
@RequestMapping("/api/fishSite")
@RequiredArgsConstructor
public class ApiFishSiteController extends BaseController {

    private final IFishSiteService fishSiteService;

    @SaIgnore
    @GetMapping("/search/options")
    public R<List<String>> searchOption(String type) {
        return R.ok(fishSiteService.searchOptions(type));
    }


    @SaIgnore
    @GetMapping("/hot")
    public R<List<FishSiteVo>> hot() {
        return R.ok(fishSiteService.hot());
    }

    /**
     * 分页查询公开的钓点数据
     * @param pageQuery 分页数据
     * @param body 查询条件
     * @return 钓点数据
     */
    @SaIgnore
    @PostMapping("/list")
    public R<TableDataInfo<FishSiteVo>> pageList(PageQuery pageQuery, @RequestBody FishSiteParam body) {
        return R.ok(fishSiteService.customerPageList(body, pageQuery));
    }

    /**
     * 查询用户自己的保存的钓点数据
     * @param pageQuery 分页参数
     * @return 钓点数据
     */
    @GetMapping("user/list")
    public R<TableDataInfo<FishSiteVo>> list(PageQuery pageQuery) {
        FishSiteBo fishSiteBo = new FishSiteBo();
        fishSiteBo.setUserId(LoginHelper.getUserId());
        return R.ok(fishSiteService.queryPageList(fishSiteBo, pageQuery));
    }

    /**
     * 查询用户收藏钓点
     * @param pageQuery 分页参数
     * @return 钓点数据
     */
    @GetMapping("user/collect/list")
    public R<TableDataInfo<FishSiteVo>> listUserCollectFishSIte(PageQuery pageQuery) {
        return R.ok(fishSiteService.queryPageListUserCollectFishSite(pageQuery, LoginHelper.getUserId()));
    }

    @SaIgnore
    @GetMapping("/get/public/{fishSiteId}")
    public R<FishSiteDetailVo> getPublicDetail(@PathVariable Long fishSiteId) {
        return R.ok(fishSiteService.getPublicDetail(fishSiteId));
    }


    /**
     * 修改钓场公开状态
     * @return 无
     */
    @PostMapping("/public")
    public R<Void> modifyPublic(@RequestBody FishSiteBo body) {
        fishSiteService.modifyPublic(body.getFishSiteId(), body.getPublicFlag(), LoginHelper.getUserId());
        return R.ok();
    }

    /**
     * 修改钓点信息
     * @param body 钓点信息
     * @return 无
     */
    @PostMapping("/update")
    public R<Void> update(@RequestBody FishSiteBo body) {
        fishSiteService.updateByBo(body);
        return R.ok();
    }

    /**
     * 保存鱼塘
     */
    @PostMapping("/save")
    public R<Void> save(@RequestBody FishSiteBo body) {
        fishSiteService.save(body, LoginHelper.getUserId());
        return R.ok();
    }

    @PostMapping("delete")
    public R<Void> delete(@Validated @RequestBody DelParam delForm) {
        // 1 删除钓点
        fishSiteService.delete(delForm.getIds(), LoginHelper.getUserId());
        return R.ok();
    }
}
